<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>computed</title>
</head>

<body>
    <div id="app">
        <input type="text" v-model="msg">
        <!-- 计算属性 -->
        <div>{{reverseString}}</div>
        <!-- 方法 -->
        <div>{{reverseMessage()}}</div>

        <input type="text" v-model.number="dataA">
        <input type="text" v-model.number="dataB">
        <div>{{dataSum}}</div>
    </div>

    <script type="text/javascript" src="js/vue.js"></script>
    <script type="text/javascript">
        var vm = new Vue({
            el: '#app',
            data: {
                msg: 'Hello Vue !',
                dataA: 0,
                dataB: 0,
                dataC: 0
            },
            methods: {
                reverseMessage: function () {
                    console.log('执行了方法')
                    return this.msg.split('').reverse().join('');
                }
            },
            computed: {
                reverseString: function () {
                    console.log('执行了计算属性');
                    return this.msg.split('').reverse().join('');
                },
                dataSum: function () {
                    this.dataC = this.dataA + this.dataB;
                    return this.dataC;
                }
            }
        });
    </script>
</body>

</html>